package com.dongdongshop.controller;


import com.dongdongshop.data.Result;
import com.dongdongshop.pojo.TbContent;
import com.dongdongshop.pojo.TbContentCategory;
import com.dongdongshop.service.ContentCategoryService;
import com.sun.org.apache.regexp.internal.RE;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("/contentCategory")
@Controller
public class ContentCategoryController {


    @DubboReference
    private ContentCategoryService contentCategoryService;

    @RequestMapping("/toContentCategory")
    public String toShow(){
        return "/admin/content_category";
    }

    @RequestMapping("/listContentCategory")
    @ResponseBody
    public Result listContentCategory(){
        try {
            List<TbContentCategory> list = contentCategoryService.listContentCategory();
            return Result.OK().setData(list);
        }catch (Exception e){

            return Result.ER();
        }
    }
    @RequestMapping("/addCate")
    @ResponseBody
    public Result saveCate(TbContentCategory tbContentCategory){
        try {
            contentCategoryService.addCate(tbContentCategory);
            return Result.OK();
        }catch (Exception e){

            return Result.ER();
        }
    }
    @RequestMapping("/toupdate")
    @ResponseBody
    public Result toupdate(Long id){
        try {
            TbContentCategory list = contentCategoryService.toupdate(id);
            return Result.OK().setData(list);
        }catch (Exception e){

            return Result.ER();
        }
    }
    @RequestMapping("/updateCate")
    @ResponseBody
    public Result updateCate(TbContentCategory tbContentCategory){
        try {
            contentCategoryService.updateCate(tbContentCategory);
            return Result.OK();
        }catch (Exception e){

            return Result.ER();
        }
    }
    @RequestMapping("/delCategory")
    @ResponseBody
    public Result delCategory(@RequestParam(value = "ids")List<Long> ids){
        try {
            contentCategoryService.delCate(ids);
            return Result.OK();
        }catch (Exception e){

            return Result.ER();
        }
    }
}
